package me.buick.util.jmeter.snmp.snmpmgmt;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.jmeter.samplers.SampleResult;
import org.apache.jorphan.logging.LoggingManager;
import org.apache.log.Logger;
import me.buick.util.snmp.core.pojo.DiskIOPojo;
import me.buick.util.snmp.core.pojo.DiskUsagePojo;
import me.buick.util.snmp.core.pojo.NetworkInfoPojo;

/**
 * 
 * Version 1.0
 * 
 * @author buick
 *
 */
public class SNMPSampleResult extends SampleResult {
	
	private static final long serialVersionUID = -1555976628502183631L;

	static final Logger log = LoggingManager.getLoggerForClass();
	
	private SNMPSampleResult preSampleResult;
	private SNMPSampleResultProcessor processor;
	
	private List<String> resultNameList = new ArrayList<String>();
	private List<Long>    resultList = new ArrayList<Long>();   
	
	private long timeStamp;
	
	//configuration settings
	private String server;
	private String port;
	private String serverType;
	private String snmpSuiteID;
	private String snmpDataRetriveInterval;

	private double cpuLoad;
	private java.util.Date date;

	//System info data
	private long mem;
	private long memUsage;
	private double memLoad;
	
	//control
	private boolean isLoad = false;
	
	public boolean isLoad() {
		return isLoad;
	}

	public void setLoad(boolean isLoad) {
		this.isLoad = isLoad;
	}

	//Disk Partition & IO info
	private Map<String,DiskIOPojo> diskPartitionsIO = new HashMap<String, DiskIOPojo>();//disk partition name
	
	//Disk Partition & Partition size
	private Map<String,DiskUsagePojo> diskPartitions = new HashMap<String, DiskUsagePojo>();
	
	private Map<String,Double> processorLoad = new HashMap<String, Double>();
	
	private Map<String, NetworkInfoPojo> networkIO = new HashMap<String, NetworkInfoPojo>();
	
	public String getSnmpDataRetriveInterval() {
		return snmpDataRetriveInterval;
	}

	public void setSnmpDataRetriveInterval(String snmpDataRetriveInterval) {
		this.snmpDataRetriveInterval = snmpDataRetriveInterval;
	}

	public java.util.Date getDate() {
		return date;
	}

	public void setDate(java.util.Date date) {
		this.date = date;
	}
	
	public Map<String, Double> getProcessorLoad() {
		return processorLoad;
	}

	public void setProcessorLoad(Map<String, Double> processorLoad) {
		this.processorLoad = processorLoad;
	}

	public Map<String, NetworkInfoPojo> getNetworkIO() {
		return networkIO;
	}

	public void setNetworkIO(Map<String, NetworkInfoPojo> networkIO) {
		this.networkIO = networkIO;
	}

	public void setDiskPartitions(Map<String,DiskUsagePojo> diskPartitions) {
		this.diskPartitions = diskPartitions;
	}
	
	public Map<String,DiskUsagePojo> getDiskPartitions() {
		return this.diskPartitions;
	}

	public double getCpuLoad() {
		return cpuLoad;
	}

	public void setCpuLoad(double cpuLoad) {
		this.cpuLoad = cpuLoad;
	}

	public double getMemLoad() {
		return memLoad;
	}

	public void setMemLoad(double memLoad) {
		this.memLoad = memLoad;
	}

	private long sysUptime = -1L;
	
	public SNMPSampleResult(){
		this.sysUptime = 0L;
		this.timeStamp = 0L;
	}

	public SNMPSampleResult(SNMPSampleResultProcessor processor){
		this.processor = processor;
	}

	public long getMem() {
		return mem;
	}

	public void setMem(long mem) {
		this.mem = mem;
	}

	public long getMemUsage() {
		return memUsage;
	}

	public void setMemUsage(long memUsage) {
		this.memUsage = memUsage;
	}

	public long getSysUptime() {
		return sysUptime;
	}

	public void setSysUptime(long sysUptime) {
		this.sysUptime = sysUptime;
	}

	public Map<String, DiskIOPojo> getDiskPartitionsIO() {
		return diskPartitionsIO;
	}

	public void setDiskPartitionsIO(Map<String, DiskIOPojo> diskPartitionsIO) {
		this.diskPartitionsIO = diskPartitionsIO;
	}
	
	public String getServer() {
		return server;
	}

	public void setServer(String server) {
		this.server = server;
	}

	public String getPort() {
		return port;
	}

	public void setPort(String port) {
		this.port = port;
	}

	public String getServerType() {
		return serverType;
	}

	public void setServerType(String serverType) {
		this.serverType = serverType;
	}

	public SNMPSampleResult getPreSampleResult() {
		return preSampleResult;
	}

	public void setPreSampleResult(SNMPSampleResult preSampleResult) {
		this.preSampleResult = preSampleResult;
	}

	public long getUpTime() {
		return this.sysUptime;
	}

	public void setUpTime(long upTime) {
		this.sysUptime = upTime;
	}

	public long getTimeStamp() {
		return timeStamp;
	}

	public void setTimeStamp(long timeStamp) {
		this.timeStamp = timeStamp;
	}

	public String getSnmpSuiteID() {
		return snmpSuiteID;
	}

	public void setSnmpSuiteID(String snmpSuiteID) {
		this.snmpSuiteID = snmpSuiteID;
	}

	public SNMPSampleResultProcessor getProcessor() {
		return processor;
	}

	public void setProcessor(SNMPSampleResultProcessor processor) {
		this.processor = processor;
	}

	public List<String> getResultNameList() {
		return resultNameList;
	}

	public void setResultNameList(List<String> resultNameList) {
		this.resultNameList = resultNameList;
	}

	public List<Long> getResultList() {
		return resultList;
	}

	public void setResultList(List<Long> resultList) {
		this.resultList = resultList;
	}
	
	public SNMPSampleResult processSampleResult() throws Exception{
		if(this.processor != null){
			this.processor.readSampleResult(this);
			return this;
		}else{
			log.error("SNMP Result Processor Not Found");
			return null;
		}
	}
	
}
